#include "bullet.h"
#include "config.h"

bullet::bullet()
{
    //加载子弹资源
    m_bullet.load(BULLET_PATH);

    //子弹坐标
    m_X=0;
    m_Y=(GAME_HEIGHT-m_bullet.height())*0.5;

    //子弹的状态
    m_Free=true;

    //子弹速度
    m_speed=BULLET_SPEED;

    //子弹的边框
    m_Rect.setWidth(m_bullet.width());
    m_Rect.setHeight(m_bullet.height());
    m_Rect.moveTo(m_X,m_Y);
}

void bullet::updatePosition()
{
    //空闲子弹不计算坐标
    if(m_Free)
        return;

    //不空闲子弹向右运动
    m_X+=m_speed;
    m_Rect.moveTo(m_X,m_Y);

    //子弹射到右边界，变为空闲状态
    if(m_X>=GAME_WIDTH)
        m_Free=true;
}
